package gui.components.JXTable.JXRow;

import javax.swing.*;
import javax.swing.table.JTableHeader;
import java.awt.*;
import java.util.HashMap;

/**
 * Date: 06.09.2005
 * Time: 9:46:48
 */
public class JXRowHeaderRenderer extends JLabel implements ListCellRenderer {
    private HashMap<Integer,Color> rows = new HashMap<Integer, Color>();
    private Color color = null;
    public void addColorHeaderRow(Integer row, Color color){
        rows.put(row,color);
    }
    public void removeColorHeaderRow(Integer row){
        if(rows.containsKey(row)){
            rows.remove(row);
        }
    }
    public JXRowHeaderRenderer(JTable table) {
        JTableHeader header = table.getTableHeader();
        setOpaque(true);
        setBorder(UIManager.getBorder("TableHeader.cellBorder"));
        setHorizontalAlignment(CENTER);
        setForeground(header.getForeground());
        setBackground(header.getBackground());
        color = header.getBackground();
        setFont(header.getFont());
    }

    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        setText((value == null) ? "" : value.toString());
        if(rows.containsKey(index)){setBackground(rows.get(index));}else{setBackground(color);}
        return this;
    }
}